package top.humbleyuan.linkedlist;

import top.humbleyuan.datastructure.linkedlist.LinkNode;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 22:47
 * @Des 链表的中间节点
 */
public class LeetCode_876 {
    // 快慢指针
    public static void main(String[] args) {
        /**
         * 数据准备
         */
        LinkNode head = new LinkNode(6);
        int[] vals = {2,3,5,7,8};
        head = LinkNode.formLink(head,vals);
        LinkNode.headToString(head);

        if(head.next == null) {
            System.out.println(head.val);
            return;
        }


        LinkNode fast = head.next.next;
        LinkNode slow = head;

        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }

        System.out.println(slow.next.val);
    }
}
